package com.dlc.yunguang.net.protocol;

import android.text.TextUtils;

import com.dlc.yunguang.net.bean.BackBean;
import com.dlc.yunguang.net.bean.HandworkBean;
import com.dlc.yunguang.net.bean.HotelBean;
import com.dlc.yunguang.net.bean.OrderCheckBean;
import com.dlc.yunguang.net.bean.OrderRfidsBean;
import com.dlc.yunguang.net.bean.SimpleBean;
import com.dlc.yunguang.net.bean.WashOrderBean;
import com.dlc.yunguang.net.bean.WashOrderDetailBean;
import com.dlc.yunguang.net.protocol.base.HttpProtocol;
import com.lzy.okgo.model.HttpParams;
import rx.Observable;

/**
 * 订单网络访问
 */
public class OrderProto extends HttpProtocol {

    private OrderProto() {
    }

    private static class InstanceHolder {
        private static final OrderProto sProtocol = new OrderProto();
    }

    public static OrderProto get() {
        return InstanceHolder.sProtocol;
    }

    /**
     * 送洗订单
     * @param page
     * @param pageSize
     * @param type
     * @return
     */
    public Observable<WashOrderBean> orderWash(String page, String pageSize, int type, String hotel_id) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("page", page);
        httpParams.put("pagesize", pageSize);
        httpParams.put("type",type);
        if(hotel_id != null){
            httpParams.put("hotel_id'",hotel_id);
        }
        return rxPost("order_wash", httpParams, WashOrderBean.class, true, null);
    }

    /**
     * 租赁订单
     * @param page
     * @param pageSize
     * @param type
     * @return
     */
    public Observable<WashOrderBean> orderRent(String page, String pageSize, int type,String hotel_id) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("page", page);
        httpParams.put("pagesize", pageSize);
        httpParams.put("type",type);
        if(hotel_id != null){
            httpParams.put("hotel_id'",hotel_id);
        }
        return rxPost("order_rent", httpParams, WashOrderBean.class, true, null);
    }

    /**
     * 送洗订单详情
     * @param id
     * @return
     */
    public Observable<WashOrderDetailBean> orderWashDetail(String id, String orderno) {
        HttpParams httpParams = new HttpParams();
        if(id != null) {
            httpParams.put("id", id);
        }
        if(orderno != null) {
            httpParams.put("orderno", orderno);
        }
        return rxPost("order_wash_detail", httpParams, WashOrderDetailBean.class, true, null);
    }
    public Observable<OrderRfidsBean> order_rfids(String read_rfids, String orderno) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("rfids", read_rfids);
        httpParams.put("orderno", orderno);
        return rxPost("order_rfids", httpParams, OrderRfidsBean.class, true, null);
    }
    /**
     * 送货订单详情
     * @param id
     * @param orderno
     * @return
     */
    public Observable<WashOrderDetailBean> orderDeliverDetail(String id,String orderno) {
        HttpParams httpParams = new HttpParams();
        if(id != null) {
            httpParams.put("id", id);
        }
        if(orderno != null) {
            httpParams.put("orderno", orderno);
        }
        return rxPost("order_deliver_detail", httpParams, WashOrderDetailBean.class, true, null);
    }


    /**
     * 分发订单详情
     * @param id
     * @return
     */
    public Observable<WashOrderDetailBean> rfid_wash_detail(String id,String orderno) {
        HttpParams httpParams = new HttpParams();
        if(id != null) {
            httpParams.put("id", id);
        }
        if(orderno != null) {
            httpParams.put("orderno", orderno);
        }
        return rxPost("rfid_wash_detail", httpParams, WashOrderDetailBean.class, true, null);
    }

    /**
     *租赁订单详情
     * @param id
     * @return
     */
    public Observable<WashOrderDetailBean> orderRentDetail(String id) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("id", id);
        return rxPost("order_rent_detail", httpParams, WashOrderDetailBean.class, true, null);
    }

    /**
     * 获取酒店列表
     * @return
     */
    public Observable<HotelBean> getHotel() {
        return rxPost("hotel", null, HotelBean.class, true, null);
    }

    public Observable<SimpleBean> getOffice() {
        return rxPost("office", null, SimpleBean.class, true, null);
    }


    /**
     * 送货交接
     * @param orderno
     * @return
     */
    public Observable<BackBean> orderDeliverReceive(String orderno, String rfids) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("orderno", orderno);
        httpParams.put("rfids", rfids);
        return rxPost("order_deliver_receive", httpParams, BackBean.class, true, null);
    }

    /**
     * 送洗交接
     * @param orderno
     * @return
     */
    public Observable<SimpleBean> orderWashReceive(String orderno,String rfids) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("orderno", orderno);
        httpParams.put("rfids", rfids);
        return rxPost("order_wash_receive", httpParams, SimpleBean.class, true, null);
    }

    public Observable<OrderCheckBean> rfid_compare(String read_rfids, String rfids) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("read_rfids", read_rfids);
        httpParams.put("rfids", rfids);
        return rxPost("rfid_compare", httpParams, OrderCheckBean.class, true, null);
    }
    public Observable<SimpleBean> manual_record(String hotel_id, String title,String nums,String type,String receivetime) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("hotel_id", hotel_id);
        httpParams.put("title", title);
        httpParams.put("nums", nums);
        httpParams.put("type", type);
        httpParams.put("receivetime", receivetime);
        return rxPost("manual_record", httpParams, SimpleBean.class, true, null);
    }
    public Observable<HandworkBean> get_record(String hotel_id, String start, String end) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("hotel_id", hotel_id);
        if (!TextUtils.isEmpty(start)) {
            httpParams.put("start", start);
        }
        if (!TextUtils.isEmpty(end)) {
            httpParams.put("end", end);
        }
        return rxPost("get_manual", httpParams, HandworkBean.class, true, null);
    }
}
